﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace masini
{
    class MiniPool : CarsFactory
    {
        static MiniPool _instance;
        List<MiniCar> cars;

        private MiniPool()
        {
            cars = new List<MiniCar>();
            cars.Add(new MiniCar("mercedes", "verde", "manuala", "ac", "diesel", "1m"));
            cars.Add(new MiniCar("bmw", "verde", "manuala", "mp3-player", "diesel", "1.3m"));
            cars.Add(new MiniCar("audi", "verde", "manuala", "jante aliaj", "diesel", "1.1m"));

        }

        public static MiniPool Instance()
        {
            if (_instance == null)
            {
                _instance = new MiniPool();
            }

            return _instance;
        }

        public override void Put(Car s)
        {
            if (s.GetType().ToString().Split('.')[1] == "MiniCar")
                cars.Add((MiniCar)s);
            else
                Console.WriteLine("Tipul masini nu corespunde cu pool-ul");
        }

        public override Car SearchByName(string name, bool sterge)
        {
            Car aux = new MiniCar();
            bool ok = false;
            foreach (Car c in cars)
            {
                if (c.getName() == name)
                {
                    aux = c;
                    ok = true;
                }
            }
            if (ok == true)
            {
                if (sterge)
                    cars.Remove((MiniCar)aux);
                return aux;
            }

            return new MiniCar();
        }
        
    }
}
